﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynaSpace.Entity;
using Microsoft.Xna.Framework;

namespace DynaSpace.Game1
{
	/// <summary>
	/// Statická třída sloužící ke generování map
	/// </summary>
	public static class MapGenerator
	{
		private static Random r = new Random();

		/// <summary>
		/// Vygeneruje náhodou mapu do předané hry
		/// </summary>
		/// <param name="p">Hra, do které se bude generovat mapa</param>
		public static void GenerateMap(Playground p)
		{
			p.Map.Clear(); // smazat predchozi entity
			p.Players.Clear(); // smazat hráče

			int groundLevel = p.Map.Height / 2 + 1;

			//for (int x = 1; x < p.Map.Width - 1; x++)
			//{
			//    float posyOffset = (float)(Math.Sin((double)x / 3) * 4);
			//    for (int y = groundLevel; y < p.Map.Height - 1; y++)
			//    {
			//        p.Map.Add(new GroundEntity(p, new Vector2(x, posyOffset + y), y == groundLevel ? GroundEntityType.Ground1_Grass : GroundEntityType.Ground0_Deep));
			//    }
			//}

			//for (int x = 0; x < p.Map.Width; x++)
			//{
			//    p.Map.Add(new GroundEntity(p, new Vector2(x, 0), GroundEntityType.Ground2_Stone));
			//    p.Map.Add(new GroundEntity(p, new Vector2(x, p.Map.Height - 1), GroundEntityType.Ground2_Stone));
			//}

			//for (int y = 0; y < p.Map.Height; y++)
			//{
			//    p.Map.Add(new GroundEntity(p, new Vector2(0, y), GroundEntityType.Ground2_Stone));
			//    p.Map.Add(new GroundEntity(p, new Vector2(p.Map.Width - 1, y), GroundEntityType.Ground2_Stone));
			//}


			//// náhodné kostky
			//var r = new Random();
			//for (int i = 0; i < 50; i++)
			//{
			//    p.Map.Add(new GroundEntity(p, new Vector2(r.Next(1, p.Map.Width - 1), r.Next(4, p.Map.Height - 1)), GroundEntityType.Ground1_Grass));
			//}

			Player p2 = new Player(p, new Vector2(2f, 2), PlayerIndex.Two);
			Player p1 = new Player(p, new Vector2(p.Map.Width - 2f, 2), PlayerIndex.One);


			p.Players.Add(p1);
			p.Players.Add(p2);
			p.Map.Add(p1);
			p.Map.Add(p2);
		}
	}
}
